home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Windows News 2010 Summer - Disc 1
/
WN_Ete2010_CD1.iso
/
Onglet5
/
Weezo
/
Weezo setup.exe
/
{code_appDir}
/
www
/
local
/
pluginsManagement.php
< prev
next >
Wrap
PHP Script
|
2010-05-19
|
16KB
|
450 lines
<?php
/**
* Plugins management script
*
*
*
* PHP version 5
*
* LICENSE: This source file is subject to version 3.0 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to license@php.net so we can mail you a copy immediately.
*
* @category NA
* @package NA
* @author Nicolas Bruley / Peer 2 World <contact@weezo.net>
* @copyright 2005-2009 Nicolas Bruley / Peer 2 World
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version CVS: $Id:$
* @link http://www.weezo.net
* @since File available since Release 2.0.0
*/
define('PLUGINS_VERSIONS_UPDATE_TIME',21600); // Time between 2 refresh
define('WINDOW_REDUCEDSIZE','"600x128"'); // reduced (download) size window
define('WINDOW_FULLSIZE','"600x600"'); // full size window
/**
* @desc Display plugin box
*
* @param array $plugin
* @param string $key
*/
function pluginBox($plugin,$key){
if(isset($plugin['installedVersion']) && @$plugin['isUpdateAvailable']) $extraClass='installUpdated';
elseif(isset($plugin['installedVersion'])) $extraClass='installInstalled';
else $extraClass='installNew';
echo outDivFrame('frame2 '.$extraClass);
// Preview image
echo '<img style="width:64;height:48;float:right;margin-left:2em;margin-bottom:1em;margin-right:1em;margin-top:0.5em;visibility:hidden;border:1px solid #888" onload="fade(this)" alt="" src="'.$plugin['resourcePreviewImage'].'" onmouseover="tooltip(this,\'<img src=\\\''.$plugin['resourcePreviewImage'].'\\\'>\')">';
// Icon and name
echo '<div class="frame2Header"><img src="'.$plugin['resourceIconSmall'].'" style="vertical-align:middle;margin-right:1em">'.cfUTF8Encode($plugin['name']).'</div>';
// Description
echo '<div style="text-align:justify" title="'.((strlen(@$plugin['description'])>200)?(str_ireplace('<br>',' ',@$plugin['description'])):'').'">';
if(isset($plugin['description'])) echo (cfStrTruncate($plugin['description'],200)); else echo cfCaption('genNoDescription');
echo '</div>';
echo '<br clear="all">';
// Require MySQL
if(@$plugin['requireMySQL'] && !cfMySQLInstalled()) echo '<div class="extendedWarning">'.outImage(outIcon('warning'),false,false,'float:left').'<center>'.cfCaption('extMySQLRequired').'</center></div>';
$l=$r='';
// Plugin already installed
if(isset($plugin['installedVersion'])){
// Update available
if(@$plugin['isUpdateAvailable']) {
$l.=outImage(outIcon('info2'),false,false,'margin-top:8px;margin-right:0.5em;display:inline');
$l.='<fieldset style="margin-right:2em">';
// Installed version
$l.=cfCaption('versionInstalled').cfCaption('genSeparator').(($plugin['installedVersion'])?$plugin['installedVersion']:'?');
// New available version
$l.='<div class="warning">'.cfCaption('versionLatest').cfCaption('genSeparator').$plugin['latestVersion'].'</div>';
$l.='</fieldset>';
$l.=outButton(cfCaption('genUpdate'),"javascript:update('".$key."')",outIcon('dl2'));
}
else{
// Green colored installed version
$l.='<span style="color:#3A3">'.cfCaption('versionInstalled').cfCaption('genSeparator').(($plugin['installedVersion'])?$plugin['installedVersion']:'?').'</span>';
}
// Remove resource button
if($plugin['uninstallAllowed']) $r.=outButton(cfCaption('genDelete'),"javascript:uninstall('".$key."','".addslashes($plugin['name'])."',".$plugin['installedNb'].")",outIcon('del'));
}
// Plugin not installed
else{
$l.=cfCaption('versionLatest').cfCaption('genSeparator').$plugin['latestVersion'];
$r.=outButton(cfCaption('genDownload').' / '.cfCaption('genInstall'),"javascript:install('".$key."')",outIcon('dl2'));
}
// Insert into footer
echo outFrameFooterTable('frame2Footer','<b>'.$l.'</b>',$r);
echo "</div>\n";
}
/**
* Compare current version and latest, return true if latest>current
*
* @param string $current: current version number, separated by dots
* @param string $latest: latest version number, separated by dots
* @return unknown
*/
function isUpdateAvailable($current,$latest){
if($latest===$current) return false;
$current=explode('.',$current);
$latest=explode('.',$latest);
foreach ($latest as $pos=>$value) if($value>@$current[$pos]) return true;
return false;
}
/**
* @desc return all installed and available plugins, and for installed ones, indicate if a newer version is available
*
* @return array...
*/
function pluginGetList(){
$plugins=array();
$lng=cfGGetVar('language');
$updatesAvailable=0;
// Count number of installations of plugins
$createdResources=array();
foreach (cfMGetVar('weezoResourcesList') as $id=>$file){
if(cfArrayItem(cfMGetVar('weezoResData'.$id),'type')=='misc' || cfArrayItem(cfMGetVar('weezoResData'.$id),'subType')=='phpMyAdmin') @$createdResources[strtolower(cfArrayItem(cfMGetVar('weezoResData'.$id),'subType'))]++;
}
/**
* Download latest versions list
*/
if(!is_array($latestVersions=cfMGetVar('weezoPluginsVersion')) || @$latestVersions['time']<(time()-PLUGINS_VERSIONS_UPDATE_TIME)) {
$pluginsVersion=@cfSocketHTTPRequest(DOWNLOAD_SITE.'/plugins/versions');
file_put_contents(cfAppTempDir().'/tmp_plugins',$pluginsVersion);
$latestVersions=parse_ini_file(cfAppTempDir().'/tmp_plugins',true);
@unlink(cfAppTempDir().'/tmp_plugins');
// If download OK
if(is_array($latestVersions)) {
// Set "version" file download time
$latestVersions['time']=time();
// Remove spaces from keys
foreach ($latestVersions as $key=>$value) if(strpos($key,' ')){
$value['name']=$key;
$latestVersions[str_replace(' ','',$key)]=$value;
unset($latestVersions[$key]);
}
}
cfMSetVar('weezoPluginsVersion',$latestVersions);
}
/**
* Check installed plugins versions and number of created resources
*/
// Add MySQL/phpMyAdmin
if($MySQL=cfArrayItem(cfMGetVar('weezoResourcesDefinitions'),'administration','phpMyAdmin')){
$MySQL=array('MySQL'=>$MySQL);
}
else
$MySQL=array();
$resourcesUsingMySQL=0;
// Add ffmpeg
if(cfFfmpegVersion()=='GPL')
$plugins['ffmpeggpl']=array(
'name'=>'FFmpeg GPL',
'installedNb'=>-1,
'uninstallAllowed'=>false,
'installedVersion'=>(file_exists(cfAppBinDir().'/ffmpeg/version.txt'))?file_get_contents(cfAppBinDir().'/ffmpeg/version.txt'):((filesize(cfAppBinDir().'/ffmpeg/weezoFfmpeg.exe')==5965312)?0.5:0),
'resourceIconSmall'=>outIcon('ffmpeg')
);
// Browse installed resources
$installed=cfArrayItem(cfMGetVar('weezoResourcesDefinitions'),'misc'); if(!is_array($installed)) $installed=array();
foreach ($MySQL+$installed as $key=>$resDefId){
$resData=cfMGetVar($resDefId);
$describerData=@$resData['describer'];
// Plugin's name
$plugins[strtolower($key)]['name']=$key;
$key=strtolower($key);
if(isset($describerData[$lng]['name'])) $plugins[$key]['name']=$describerData[$lng]['name'];
elseif(isset($describerData['en']['name'])) $plugins[$key]['name']=$describerData['en']['name'];
// Installed version
$plugins[$key]['installedVersion']=(isset($describerData['version']))?$describerData['version']:0;
// Number of resources using this plugin
$plugins[$key]['installedNb']=(int)@$createdResources[$key];
// Description (utf8 encoded)
if(isset($describerData[$lng]['description'])) $plugins[$key]['description']=($describerData[$lng]['description']);
elseif(isset($describerData['en']['description'])) $plugins[$key]['description']=($describerData['en']['description']);
// Preview image URL
$plugins[$key]['resourcePreviewImage']=$resData['resourcePreviewImage'];
// 32x32 icon URL
$plugins[$key]['resourceIconSmall']=$resData['resourceIconSmall'];
// Extension requires MySQL to be installed
if(@$describerData['requireMySQL']) {
$plugins[$key]['requireMySQL']=true;
$resourcesUsingMySQL+=$plugins[$key]['installedNb'];
}
// Plugin may be uninstalled
$plugins[$key]['uninstallAllowed']=true;
// MySQL mods
if($key=='mysql') {
$plugins[$key]['name']='MySQL / phpMyAdmin';
$plugins[$key]['installedNb']=(int)@$createdResources['phpmyadmin'];
if($plugins[$key]['installedVersion']) $plugins[$key]['resourceIconSmall']='/res/administration/phpMyAdmin/combinedIcon.png';
}
}
if(isset($plugins['mysql'])) $plugins['mysql']['installedNb']+=$resourcesUsingMySQL;
/**
* Combine information from non-installed plugins, and add latest version info
*/
foreach ($latestVersions as $key=>$latestVersion) if($key!=='time') {
if(isset($latestVersion['name'])) $name=$latestVersion['name']; else $name=$key;
$key=strtolower($key);
// Latest available version
$plugins[$key]['latestVersion']=$latestVersion['version'];
if($plugins[$key]['isUpdateAvailable']=isUpdateAvailable(@$plugins[$key]['installedVersion'],$latestVersion['version'])) $updatesAvailable++;
// Fill name
if(!isset($plugins[$key]['name'])) $plugins[$key]['name']=$name;
// Fill description
if(!isset($plugins[$key]['description']) && isset($latestVersion['description']) && is_array($latestVersion['description'])) {
foreach ($latestVersion['description'] as $k=>$desc){
if(substr($desc,0,2)==$lng || substr($desc,0,2)=='en'){
$plugins[$key]['description']=str_replace('-<-','(',str_replace('->-',')',substr($desc,2))); // ( and ) couldn't be parsed by parse_ini_string
break;
}
}
}
// URL to thumbnail
if(!isset($plugins[$key]['resourcePreviewImage'])) $plugins[$key]['resourcePreviewImage']=DOWNLOAD_SITE.'/plugins/'.$key.'/preview.jpg';
// URL to icon
if(!isset($plugins[$key]['resourceIconSmall'])) $plugins[$key]['resourceIconSmall']=DOWNLOAD_SITE.'/plugins/'.$key.'/resourceIconSmall.png';
// Download URL
$plugins[$key]['downloadURL']=DOWNLOAD_SITE.'/plugins/'.$key.'/'.$name.'.weezoResource';
}
return $plugins;
}
/**
* @desc Display plugin download progress page, download plugin, and pass downloaded file to UI to finish installation
*
* @param string $key: plugin name
*/
function pluginDownload($key){
require_once(INCLUDE_DIR.'miscFunctions.php');
$key=str_replace(' ','',$key);
// Remove previous file
@unlink($localFile=cfAppTempDir().'/'.$key.'.weezoResource');
// Insert download page
cfInsertHEAD(false);
echo '<meta icon="plugins"></meta>';
echo '<meta wintitle="'.APPLICATION_NAME.'"></meta>';
?>
<script type="text/javascript">
function cancel(){
wl.UICommand('fadeSize',<?php echo WINDOW_FULLSIZE;?>);
dgi('downloadDiv').style.display="none";
wl.goURL("<?php echo $_SERVER['PHP_SELF'];?>");
}
</script>
</head>
<body>
<?php
echo '</head>';
echo '<body style="margin-top:0;margin-bottom:0">';
echo outDivFrame('frame2','id="downloadDiv" style="margin-bottom:0"');
echo '<div class="frame2Header">'.outImageIcon('fi/icoPlugin').cfCaption('logFileDownload',$key).'</div><br><center>';
// Download file
$result=mfMonitoredDownload(DOWNLOAD_SITE.'/download.php?plugin='.$key,$localFile,array('cancelHref'=>'javascript:cancel()','appendHTML'=>' '));
echo '</center></div>';
if($result) {
?>
<script type="text/javascript">
wl.UICommand('installPluginFromFile','<?php echo $localFile;?>');
</script>
<?php
}
else{
echo outDivFrame('frame2');
?>
<div class="frame2Header"><?php echo outImageIcon('warning').cfCaption('genError');?></div>
<br>
<center><?php echo outButton(cfCaption('genCancel'),'javascript:cancel()',outIcon('backRed'));?></center><br>
<script type="text/javascript">
dgi('downloadDiv').style.display="none";
wl.UICommand('fadeSize',<?php echo (WINDOW_REDUCEDSIZE-10);?>);
</script>
<?php
}
die('</body>');
}
/**
* @desc Uninstall plugin
*
* @param string $key
*/
function pluginUninstall($key){
require_once(INCLUDE_DIR.'resourceConfigFunctions.php');
// Ignore user abort to ensure resource is completely removed
ignore_user_abort(true);
if($key=='mysql'&& cfMySQLInstalled() && @cfProcessExists('mysqld.exe')) {
foreach (@win32_ps_list_procs() as $proc) if(strtolower(basename(@$proc['exe']))=='mysqld.exe') {
customTerminateProcess(@$proc['pid']);
sleep(1);
break;
}
// Remove bin directory - try 3 times as it may take a little time for file to be released after being killed
$i=3; while($i--) {
cfUnlinkDir(cfAppDataRootDir().'/MySQL/bin');
if(file_exists(cfAppDataRootDir().'/MySQL/bin/mysqld.exe')) sleep(1); else break;
}
cfUnlinkDir(cfAppDataRootDir().'/MySQL/scripts');
cfUnlinkDir(cfAppDataRootDir().'/MySQL/share');
cfUnlinkDir(cfAppDocRoot().'/res/administration/phpMyAdmin');
foreach (cfGlob(cfAppDataRootDir().'/MySQL/*.*') as $cfn) if(basename($cfn)!='MySQL.ini') @unlink($cfn);
$type='administration';
$subType='phpmyadmin';
}
else{
// Remove plugin scripts
cfUnlinkDir(cfAppDocRoot().'/res/misc/'.$key);
$type='misc';
$subType=$key;
}
// Remove resource definition from list
$weezoResourcesDefinitions=cfMGetVar('weezoResourcesDefinitions');
foreach ($weezoResourcesDefinitions[$type] as $sT=>$val) {
if(strtolower($sT)==strtolower($subType)) {
cfMUnsetVar($val);
unset($weezoResourcesDefinitions[$type][$sT]);
cfMSetVar('weezoResourcesDefinitions',$weezoResourcesDefinitions);
break;
}
}
// Remove linked resources
foreach(cfMGetVar('weezoResourcesList') as $id=>$configFilename){
$resData=cfMGetVar('weezoResData'.$id);
if(strtolower($resData['type'])==$type && strtolower($resData['subType'])==$subType){
rcDeleteResource($configFilename);
}
}
// Refresh UI resources tab
cfServerSendCmd('updateResourcesPanel',false,false);
}
if(!cfIsInApp()) die('unauthorized access');
require_once(INCLUDE_DIR.'outputFunctions.php');
//cfMUnsetVar('weezoPluginsVersion');
/**
***************************************************************************************************************************
* Proceed to download/installation
***************************************************************************************************************************
*/
if(isset($_POST['download'])) pluginDownload($_POST['download']);
if(isset($_GET['download'])) pluginDownload($_GET['download']);
// Uninstall plugin
if(isset($_POST['uninstall'])) pluginUninstall($_POST['uninstall']);
/**
***************************************************************************************************************************
* Prepare installed extensions and available extensions data
***************************************************************************************************************************
*/
$plugins=pluginGetList();
/**
***************************************************************************************************************************
* Display plugins management page
***************************************************************************************************************************
*/
cfInsertHEAD(false);
echo '<meta icon="plugins"></meta>';
echo '<meta wintitle="'.APPLICATION_NAME.'"></meta>';
echo '</head>';
echo '<body>';
echo cfScriptLink('wz_dragdrop.js');
echo outDivFrame('frame1');
echo outFrameHeaderTable('frame1Header',outImageIcon('plugins').cfCaption('resMisc'),outButton(cfCaption('configNewResource').' ('.cfCaption('genFile').')','javascript:installFile()',outIcon('fi/icoPlugin')));
// Display plugins ordered by 1)updated 2)installed 3)others
foreach ($plugins as $key=>$plugin) if(isset($plugin['installedVersion']) && @$plugin['isUpdateAvailable']) pluginBox($plugin,$key);
foreach ($plugins as $key=>$plugin) if(isset($plugin['installedVersion']) && !@$plugin['isUpdateAvailable']) pluginBox($plugin,$key);
foreach ($plugins as $key=>$plugin) if(!isset($plugin['installedVersion'])) pluginBox($plugin,$key);
echo "</div>\n"; // frame1
//cfVarDump($plugins);?>
<script type="text/javascript">
function installFile(){
wl.UICommand('installPluginFromFile');
}
function update(key){
install(key);
}
function install(key){
wl.UICommand('fadeSize',<?php echo WINDOW_REDUCEDSIZE;?>);
wl.postData({'download':key})
}
function uninstall(key,name,nbInstalled){
var capt='<?php echo addslashes(cfCaption('confirmUninstall','PLUGINNAME'));?>';
var capt2='<?php echo addslashes(cfCaption('pluginDeleteConfirm','NBRESOURCES'));?>';
capt=capt.replace(/PLUGINNAME/,name);
if(nbInstalled>0) capt+="\n\n"+capt2.replace(/NBRESOURCES/,nbInstalled);
if(confirm(capt)) {
maskShow(true,false,true);
wl.postData({'uninstall':key})
}
}
SET_DHTML()
</script>